package ControlLayer;
import java.util.*;
import ModelLayer.*;

/**
 * Controller class for the address book
 * 
 * @author (kbh) 
 * @version (2005.03.31)
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 */
public class AddressCtr
{
    private AddressBookCon addressBookCon; //reference to container class
    private static AddressCtr instance; //Singleton
    
    /**
     * Constructor for objects of class AddressCtr
     */
    public AddressCtr()
    {
        addressBookCon = addressBookCon.getInstance();
    }
    
    /**
     * Singleton method for working with only one instance of AddressCtr.
     * (not strictly necessary for controller classes (as it is for containerclasses) but might still be convenient.)
     */
    public static AddressCtr getInstance()
    {
        if(instance == null)
        {
            instance = new AddressCtr();
        }
        return instance;
    }
    
    /**
     * Returns an object of type Person
     */
    public Person getPerson(long id)
    {
        return addressBookCon.getPerson(id);
    }
    
    /**
     * creates a new instance of Person and adds it to the containerclass
     */
    public void createPerson(String name, String address, String postalCode, String city, String phone)
    {   
       addressBookCon.createPerson(name, address, postalCode, city, phone);
    }
    
    /**
     *  Removes a person from the containerclass.
     */
    public void deletePerson(long id)
    {
        addressBookCon.deletePerson(id);
        
    }
    
    /**
     *  Updates a person from the containerclass.
     */
    public void updatePerson(Person p, long id, String name, String address, String postalCode, String city, String phone)
    {
        p = getPerson(id);
        addressBookCon.updatePerson(p, name, address, postalCode, city, phone);
 
    }
    
    /**
    * prints a list of all persons registered in the system
    */
    public void listAllPersons()
    {
         addressBookCon.getAddressBook();
    }
}
